package com.project.io.demo.stream;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

public class ByteStream {


    public static void main(String[] args) throws IOException {
//        copyByte();
//        copyCharters();
//        copyLines();
//        String str = "ABCDEa123abc";
//        String str1 = "ABCDFB123abc";
//        int code = str.hashCode();
//        int code1 = str1.hashCode();
//
//        System.out.println(code);
//        System.out.println(code1);
//        System.out.println(code >>> 16);
//        System.out.println(code1 >>> 16);
//        int hashCode = code ^ (code >>> 16);
//        int hashCode1 = code1 ^ (code1 >>> 16);
//        System.out.println(hashCode);
//        System.out.println(hashCode1);
//        System.out.println(15&hashCode);
//        System.out.println(15&hashCode1);
        Map<String,String> map = new HashMap<>();
        map.put("ABCDEa123abc","123");

        System.out.println((15) & (("ABCDEa123abc".hashCode()) ^ ("ABCDEa123abc".hashCode() >>> 16)));
    }

    private static void copyCharters() throws IOException {
        System.out.println(System.currentTimeMillis());
        FileReader in = null;
        FileWriter out = null;

        try {
            in = new FileReader("c:\\aow_drv.log");
            out = new FileWriter("c:\\aow_drv_2.log");
            int c;
            while ((c = in.read()) != -1) {
                out.write(c);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (in!=null){
                in.close();
            }
            if (out!=null){
                out.close();
            }
            System.out.println(System.currentTimeMillis());
        }
    }

    private static void copyByte() throws IOException {
        System.out.println(System.currentTimeMillis());
        FileInputStream in = null;
        FileOutputStream out= null;

        try {
            in = new FileInputStream("c:\\aow_drv.log");
            out = new FileOutputStream("c:\\aow_drv_1.log");
            int c;
            while ((c=in.read()) != -1){
                out.write(c);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (in !=null){
                in.close();
            }
            if (out !=null){
                out.close();
            }
            System.out.println(System.currentTimeMillis());
        }
    }

    private static void copyLines() throws IOException {
        BufferedReader in = null;
        PrintWriter out = null;

        try {
            in = new BufferedReader(new FileReader("c:\\aow_drv.log"));
            out = new PrintWriter(new FileWriter("c:\\aow_drv_3.log"));
            String str;
            while ((str = in.readLine()) != null) {
                out.println(str);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (in != null) {
                in.close();
            }
            if (out != null){
                out.close();
            }
        }

    }
}
